package net.vmiranda.jeds.web.util;

import java.util.Map;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import net.vmiranda.jeds.core.usuarios.Usuario;


public final class Sesion {

	
	private Sesion(){}
	
	public static Object get(final String key){
		return getSessionMap().get(key);
	}
	
	public static void 	put(final  String key,final  Object value){
		getSessionMap().put(key, value);
	}
	
	
	public static void remove(final String key){
		getSessionMap().remove(key);
	}
	
	private static Map<String,Object> getSessionMap(){
		final FacesContext context = FacesContext.getCurrentInstance();
		return context.getExternalContext().getSessionMap();
	}

	public static void salir() {
		final ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
		((HttpSession)ectx.getSession(false)).invalidate(); 
	}
	
	public static Usuario getUsuario(){
		return  (Usuario)get("usuarioActual");
	}
}
